using System;
using System.Collections.Generic;
using System.IO;

namespace Gloom
{
	public static class GLFuncNameMunger
	{
		private static List<string> funcNames = new List<string>();
		
		public static void Load()
		{
			// Look at OpenTK's function names... Yes, this is a cheap trick, but it's late, and it's easy.
			funcNames = new List<string>(File.ReadAllLines(MainClass.SpecsPath + "NiceFuncNames.txt"));
			
			// TODO: Eliminate duplicates from the .txt file at some point...
		}
		
		public static string GetManagedGLFuncName(string name)
		{
			string outp = name;
			
			string ext = outp.Substring(name.Length - 3, 3);
			if (ext != ext.ToUpper())
			{
				ext = outp.Substring(name.Length - 2, 2);
				if (ext != ext.ToUpper())
					ext = "";
				else
					outp = name.Substring(0, name.Length - 2);
			}
			else
				outp = name.Substring(0, name.Length - 3);
			
			for (int i = 1; i < 4; i++)
			{
				string stub = name.Substring(0, name.Length - i);
				
				foreach (string fn in funcNames)
					if (fn == stub)
					{
						outp = fn;
						break;
					}
				
				if (outp != name)
					break;
			}
			
			return outp + ext;
		}
	}
}

